//
// Created by YeMingMing on 2024-03-06.
//

#include <stdio.h>
void swap(int *x, int *y) {
    int temp = *y;
    *y = *x;
    *x = temp;
}


int kth_emlem(int *nums,int n,int k) {
    int low = 0, high = n-1;
    int i, j, t;
    do {
        i = low, j = high, t= nums[i];
        do {
            while (nums[j] > t) j--;
            while (nums[i] < t) i++;
            if (i < j) {
                swap(&nums[i],&nums[j]);
            }
            else {
                break;
            }
        }while (i < j);
        if (i == k) {
            return nums[i];
        }
        else if (i > k) {
            high = i-1;
        }
        else {
            low = i+1;
        }
    }while (low < high);

    return nums[low];
}


int main() {
    int nums[] = {0,5,4,7,8,6,3};
    int x = kth_emlem(nums,7,5);
    printf("%d",x);
}